<html>
<head>
<meta charset="iso-8859-1">
<link rel="stylesheet" href="../brython.css">

<script src="../brython_builtins.js"></script>
<script src="../py2js.js"></script>
<script src="../py_utils.js"></script>
<script src="../py_classes.js"></script>
<script src="../py_import.js"></script>
<script src="../py_list.js"></script>
<script src="../py_string.js"></script>
<script src="../py_dom.js"></script>
<script src="../py_ajax.js"></script>

<script type="text/python">
import sys
import time
import random
import dis

if sys.has_local_storage:
    from local_storage import storage
else:
    storage = False

_rand=random.random()   #do we need to have a new random number each time
                        #we load a module, during a single execution?
                        #probably okay to use cached module if module is 
                        #needed again during a single execution.
output = ''

sys.stdout = object()
def write(data):
    doc["console"].value += str(data)
sys.stdout.write = write

sys.stderr = object()
sys.stderr.write = write

#def to_str(x):     # we aren't using this function
#    return str(x)

def clear_text():
    doc["src"].value=''
    doc["console"].value=''

# override log to send output to textarea
def log(data):
    doc["console"].value = doc["console"].value+str(data)+'\n'

# load a Python script
def on_complete(req):
    doc["src"].value = req.text

def load(_name):
    req = ajax()
    req.on_complete = on_complete
    req.open('GET',_name+'?foo=%s' % random.random(),False)
    req.send()

def load1(evt):
    _name=evt.target.value
    req = ajax()
    req.on_complete = on_complete
    req.open('GET',_name+'?foo=%s' % _rand,False)
    req.send()

def show_console():
    doc["console"].value = output

def run():
    global output
    doc["console"].value=''
    src = doc["src"].value
    if storage:
        storage["py_src"]=src
    t0 = time.time()
    exec(src)
    output = doc["console"].value
    print('<completed in %s ms>' %(time.time()-t0))

def show_js():
    src = doc["src"].value
    doc["console"].value = dis.dis(src)
</script>
</head>
<body onload="brython(1)">
<center>
<table id="banner" cellpadding=0 cellspacing=0>
<tr>
<td><a class="banner" href="/index.html">Home</a></td>
<td><a class="banner" href="/tests/console_en.html">Console</a></td>
<td><a class="banner" href="/gallery/gallery_en.html">Gallery</a></td>
<td><a class="banner" href="/doc/en/index.html">Documentation</a>
<td><a class="banner" href="http://code.google.com/p/brython/downloads/list" target="_blank">Download</a></td>
<td><a class="banner" href="http://code.google.com/p/brython/" target="_blank">Development</a></td>
<td><a class="banner" href="/groups_en.html" target="_blank">Groups</a></td>
</tr>
</table>

<div style="text-align:center">
<img src="../brython.png"></img><br><b>browser python</b>
</div>

<p>
Choose a test suite:
<select name="filename" onChange="load1(event)">
  <option value="test_suite.py">general test suite</option>
  <option value="classes_tests.py">built-in classes</option>
  <option value="test_classes.py">classes</option>
  <option value="test_datetime.py">datetime</option>
  <option value="dom_objects.py">DOM</option>
  <option value="test_import.py">imports</option>
  <option value="issues.py">issues</option>
  <option value="test_list_methods.py">list methods</option>
  <option value="test_math.py">math</option>
  <option value="test_hashlib.py">hashlib</option>
  <option value="test_strings.py">strings</option>
</select>

<!--
<button onClick="load('test_suite.py')">test_suite.py</button>
<button onClick="load('classes_tests.py')">built-in classes</button>
<button onClick="load('test_strings.py')">strings</button>
<button onClick="load('test_math.py')">math</button>
<button onClick="load('test_hashlib.py')">hashlib</button>
<button onClick="load('test_string_methods.py')">string methods</button>
<button onClick="load('test_list_methods.py')">list methods</button>
<button onClick="load('test_classes.py')">classes</button>
<button onClick="load('issues.py')">issues</button>
<button onClick="load('dom_objects.py')">dom_objects.py</button>
-->

<p>
<table width=80%>
<tr><td style="text-align:center"><b>Python</b>
</td>
<td>&nbsp;</td>
<th><button onClick="show_console()">Console</button></th>
<th><button onClick="show_js()">Javascript</button></th>
</tr>
<tr>
<td colspan><textarea id="src" cols=60 rows=20></textarea></td>
<td><button onClick="run()">run</button>
<p>
<button onClick="clear_text()">clear</button></td>
<td colspan=2><textarea id="console" cols=60 rows=20></textarea></td>
</tr>
</table>
</center>
</body>
</html>
